// customize the interval shape, now set the rect to be a line
const Shape = F2.Shape;
const G = F2.G;
const Util = F2.Util;
const Global = F2.Global;
const Vector2 = G.Vector2;

Shape.registerShape('interval', 'tick', {
	draw: function draw(cfg, container) {
		const points = this.parsePoints(cfg.points);
		const style = Util.mix({
			stroke: cfg.color
		}, Global.shape.interval, cfg.style);
		if (cfg.isInCircle) {
			let newPoints = points.slice(0);
			if (this._coord.transposed) {
				newPoints = [points[0], points[3], points[2], points[1]];
			}

			const _cfg$center = cfg.center,
				x = _cfg$center.x,
				y = _cfg$center.y;

			const v = [1, 0];
			const v0 = [newPoints[0].x - x, newPoints[0].y - y];
			const v1 = [newPoints[1].x - x, newPoints[1].y - y];
			const v2 = [newPoints[2].x - x, newPoints[2].y - y];

			let startAngle = Vector2.angleTo(v, v1);
			let endAngle = Vector2.angleTo(v, v2);
			const r0 = Vector2.length(v0);
			const r = Vector2.length(v1);

			if (startAngle >= 1.5 * Math.PI) {
				startAngle = startAngle - 2 * Math.PI;
			}

			if (endAngle >= 1.5 * Math.PI) {
				endAngle = endAngle - 2 * Math.PI;
			}

			const lineWidth = r - r0;
			const newRadius = r - lineWidth / 2;

			return container.addShape('Arc', {
				className: 'interval',
				attrs: Util.mix({
					x,
					y,
					startAngle,
					endAngle,
					r: newRadius,
					lineWidth,
					lineCap: 'round'
				}, style)
			});
		}
	}
});